package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Staff;

public class StaffDao implements BaseStaffDao{
    static Staff[] staffs = new Staff[5];

    public Staff[] findAllStaff() {
        return staffs;
    }

    public boolean addStaff(Staff staff) {
        boolean temp = false;
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] == null){
                staffs[i] = staff;
                temp = true;
                break;
            }
        }
        return temp;
    }

    public boolean sIdExist(String sId) {
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] != null && sId.equals(staffs[i].getId())){
                return true;
            }
        }
        return false;
    }

    public void deleteStaff(String sId) {
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] != null && sId.equals(staffs[i].getId())){
                staffs[i] = null;
            }
        }
    }

    public void updateStaff(Staff updateStaff) {
        String updateId = updateStaff.getId();
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] != null && updateId.equals(staffs[i].getId())){
                staffs[i] = updateStaff;
            }
        }
    }
}
